<template>
  <view>
    <view v-for="(item,index) in list" :key="index" >
      <recordItem :listData="item" @checkDetail="checkDetail" :typeFrom="typeFrom"></recordItem>
    </view>
    <view class="tips">已显示全部</view>
  </view>
</template>

<script>
// import recordItem from '@/components/formCommon/record.vue'
import recordItem from '../components/record.vue'

export default{
  components:{
    recordItem
  },
  data(){
    return {
      formData: {
        "modeid": 1,
        "user_id":uni.getStorageSync('username'),
        "result": 0
      },
      list: [],
      typeFrom: 1
    }
  },
  props:{
    refresh: {
      type: Number,
      default: 0
    },
    filterIndex: {
      type: Number,
      default: 0
    }
  },
  watch:{
    refresh(newVal){
      if(newVal == 1){
        this.getList()
      }
    },
    // filterIndex(newVal){
    // 	this.formData.result = newVal
    // 	this.getList()
    // }
  },
  created() {
    this.getList();
  },
  methods:{
    checkDetail(e){
      console.log("准备跳转到详情页面,e:", e)
      uni.navigateTo({

        url:`/pagesOA/workOvertime/components/formCommon/detail?_id=${e._id}&type=${this.typeFrom}&id=${e.id}`
        // url:`/pages/formCommon/detail?id=${e.id}&type=${this.typeFrom}`
      })
    },
    async getList(){
      try {
        uni.showLoading({ title: '加载中...' })
        const res = await this.$api.zhy.getList(this.formData)
        if (res.code === 200 && res.data) {
          this.list = res.data
        } else {
          uni.showToast({
            icon: 'none',
            title: res.message || '获取列表失败'
          })
          console.error('获取列表失败:', res.message)
        }
      } catch (err) {
        uni.showToast({
          icon: 'none',
          title: '获取列表异常'
        })
        console.error('获取列表异常:', err)
      } finally {
        uni.hideLoading()
      }
    },
    async statsToSort(sid){
      try {
        uni.showLoading({ title: '加载中...' })
        const res = await this.$api.flow.getList(this.formData)
        if (res.code === 200 && res.data) {
          this.list = res.data
          this.list = this.list.filter(item=>{
            return item.result == sid
          })
        } else {
          uni.showToast({
            icon: 'none',
            title: res.message || '获取列表失败'
          })
          console.error('获取列表失败:', res.message)
        }
      } catch (err) {
        uni.showToast({
          icon: 'none',
          title: '获取列表异常'
        })
        console.error('获取列表异常:', err)
      } finally {
        uni.hideLoading()
      }
    }
  }
}
</script>

<style scoped>
.tips {
  color: #B2B2B2;
  width: 40%;
  margin: 20rpx auto;
  text-align: center;
}
</style>